package com.example.a429;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class Personal extends AppCompatActivity {

    private RecyclerView recyclerView;
    private ProductAdapter productAdapter;
    private Product[] products = {
            new Product("北欧风格实木餐椅", 299, R.drawable.chair), // 确保 drawable/chair.png 存在
            new Product("大理石纹茶几", 688, R.drawable.table),    // 确保 drawable/table.png 存在
            new Product("北欧风格台灯", 159, R.drawable.lamp),     // 确保 drawable/lamp.png 存在
            new Product("简约书架置物架", 399, R.drawable.bookshelf) // 确保 drawable/bookshelf.png 存在
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal);

        // 初始化 RecyclerView
        recyclerView = findViewById(R.id.product_list); // 获取 RecyclerView 控件
        // 使用 Personal.this 明确指定 Context
        recyclerView.setLayoutManager(new LinearLayoutManager(Personal.this));
        productAdapter = new ProductAdapter(products); // 创建适配器实例
        recyclerView.setAdapter(productAdapter); // 将适配器设置给 RecyclerView

        ImageButton backButton = findViewById(R.id.back_button);
        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建跳转到 MainActivity 的 Intent
                Intent intent = new Intent(Personal.this, MainActivity.class);
                // 启动 MainActivity
                startActivity(intent);
                // 关闭当前 Activity
                finish();
            }
        });
    }
}